"""
浏览一个需要登录才能看的url
1、请求头从包含cookie的信息
    F12——network 找到请求头user-agent、cookie
2、cookis参数
"""

import requests

url = 'https://gitee.com/Jbabababa/PythonCode'
h = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
    'Cookie': 'user_locale=zh-CN; oschina_new_user=false; tz=Asia%2FShanghai; Hm_lvt_24f17767262929947cc3631f99bfd274=1605765705; sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%228076167%22%2C%22first_id%22%3A%22175df182bc4468-0b571f81df25a1-333769-2073600-175df182bc57f1%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%22175df182bc4468-0b571f81df25a1-333769-2073600-175df182bc57f1%22%7D; Hm_lpvt_24f17767262929947cc3631f99bfd274=1605765831; gitee-session-n=eGk2VVREVzhQdVRxQWlCUXBCMHVza1l2WHBLWFFJUVNhdVgrM3dTSkhQc043YTFQaGVzWUJuM2k2Vy9nQzR6OThNOGdmRkxLQmQ0QVFpaWd4Wm9STnNjRzQ2VWV3S29EUTRRTjB5UXhHNGFiRWtxazcxckVrTnV2T2NXcU5Od3lEOEY5MHZXakVnMmVyMVdEaG5EV2RoRUV5THJEQW5CeC9EYnNIbHl3VVZHamhlL1AxaXRmZnRJei9oWUw4cEljU1BCemxuaG44ZUc4dlptS01NbEtqbUVCUkREK1owUFk4dkdBY2VMUUNtV0JibjZlUldzcFNYZVVDTExlQkNzZVJBaC9iaDhTQzZMMkVjYldhZFlWaDdmS1plRytXNy9yNWZHNERBNFJlT1pNN2hTamVVSVZ4dStqbGdkVlVTL2hCQlpyYzVxTDZQMG5qdjRBMy9SQW1xZEQ1clJhRmZNT21TRXc4QUt0ZXhnPS0teVpZcEhESkE5cks1QzVhcE4zZm5vQT09--4c5c03a62281f9a98c37872bf2f0cc240b74ad48'
}
r = requests.get(url, h)
print(r.content.decode())

# 2、cookies参数
h = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
}
# cookie 字符串，从浏览器拷贝
str_cookies = 'user_locale=zh-CN; oschina_new_user=false; tz=Asia%2FShanghai; Hm_lvt_24f17767262929947cc3631f99bfd274=1605765705; sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%228076167%22%2C%22first_id%22%3A%22175df182bc4468-0b571f81df25a1-333769-2073600-175df182bc57f1%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%22175df182bc4468-0b571f81df25a1-333769-2073600-175df182bc57f1%22%7D; Hm_lpvt_24f17767262929947cc3631f99bfd274=1605765831; gitee-session-n=eGk2VVREVzhQdVRxQWlCUXBCMHVza1l2WHBLWFFJUVNhdVgrM3dTSkhQc043YTFQaGVzWUJuM2k2Vy9nQzR6OThNOGdmRkxLQmQ0QVFpaWd4Wm9STnNjRzQ2VWV3S29EUTRRTjB5UXhHNGFiRWtxazcxckVrTnV2T2NXcU5Od3lEOEY5MHZXakVnMmVyMVdEaG5EV2RoRUV5THJEQW5CeC9EYnNIbHl3VVZHamhlL1AxaXRmZnRJei9oWUw4cEljU1BCemxuaG44ZUc4dlptS01NbEtqbUVCUkREK1owUFk4dkdBY2VMUUNtV0JibjZlUldzcFNYZVVDTExlQkNzZVJBaC9iaDhTQzZMMkVjYldhZFlWaDdmS1plRytXNy9yNWZHNERBNFJlT1pNN2hTamVVSVZ4dStqbGdkVlVTL2hCQlpyYzVxTDZQMG5qdjRBMy9SQW1xZEQ1clJhRmZNT21TRXc4QUt0ZXhnPS0teVpZcEhESkE5cks1QzVhcE4zZm5vQT09--4c5c03a62281f9a98c37872bf2f0cc240b74ad48'
# 将cookie字符串构造成字典
dict_cookies = {}
r = requests.get(url, h, cookies=dict_cookies)
print(r.content.decode())